$(function(){
	goToPage(1);
});
function goToPage(pageNo){
	var deviceName = $('#deviceName').val();
	$.ajax({
		url : contextPath+ 'user/zsbyq/list',
		data : {
			towerCode:deviceid,
			deviceName:deviceName,
			pageNo : pageNo,
			pageSize:10
		},
		type : 'POST',
		success : function(list) {
			$(".pwsj_right_byq_divbox").empty();
			$(".page").empty();
			if(list!=null && list.totalRecord>0){
				var obj = list.records;
				for(var i=0;i<obj.length;i++){
					var div= '<ul class="byq_cont_ul">';
					div += '<li id="deviceBox" name="deviceBox" class="" style="width:4%;"><input type="checkbox" value="'+obj[i].deviceid+'" class="checkbox" /></li>';
					div += '<li style="width:13%;"><a href="'+contextPath+'user/d/zsbyqinfo.jsp?deviceid='+obj[i].deviceid+'">'+obj[i].devicename+'</a></li>';
					div += '<li style="width:8%;">'+(obj[i].operationstate==null?"":obj[i].operationstate)+'</li>';
					div += '<li style="width:10%;">'+(obj[i].linename==null?"":obj[i].linename)+'</li>';
					div += '<li style="width:8%;">'+(obj[i].towername==null?"":obj[i].towername)+'</li>';
					div += '<li style="width:8%;">'+(obj[i].usenature==null?"":obj[i].usenature)+'</li>';
					div += '<li style="width:8%;">'+(obj[i].isruralpowernetwork==null?"":obj[i].isruralpowernetwork)+'</li>';
					div += '<li style="width:4%;">'+(obj[i].model==null?"":obj[i].model)+'</li>';
					div += '<li style="width:6%;">'+(obj[i].ratedcapacity==null?"":obj[i].ratedcapacity+'kVA')+'</li>';
					div += '<li class="operate" style="width:30%; border-right:none;">';
					//权限判断
					if(lowaddaction){
						div += '<a href="'+contextPath+'user/d/dyxladd.jsp?deviceid='+obj[i].deviceid+'&devicetype=2" class="detail_a">新增线路</a>';
					}
					if(true){
						div +=	'<a href="'+contextPath+'user/d/dyxllist.jsp?deviceid='+obj[i].deviceid+'&devicetype=2" class="detail_a">线路列表</a>';
					}
//					div += '<a href="'+contextPath+'user/d/zsbyqadd.jsp?deviceid=50f45e9d-61bc-43a3-ba93-8fc29882460d" class="detail_a">添加</a>';
					if(mediumeditaction){
						div += '<a href="'+contextPath+'user/d/zsbyqedite.jsp?deviceid='+obj[i].deviceid+'" class="detail_a">编辑</a>';
					}
					if(mediumdeleteaction){
						div += '<a href="javascript:devicedel(\'zsbyq\',\''+obj[i].deviceid+'\''+',0,0);"  class="detail_a">删除</a>';
					}
                    div += '<a  class="detail_a_del" onclick="exportExcel222(\''+obj[i].devicename+'\',\''+obj[i].deviceid+'\')">导出</a>';
					div +=	'</li>';
					div += '</ul>';
					$(".pwsj_right_byq_divbox").append(div);
				}
				pageList(list);
			}
		}
	});
}
function batchedit(){
	var ids="";
	$(':checkbox:checked').each(function(index){
		if(index==0){
			ids +=$(this).val();
		}else{
			ids +=  ","+$(this).val();
		}
	})
	if(ids!=""){
		location.href=contextPath+"user/d/pdbyqbatchedit.jsp?deviceid="+ids;
	}
}
function exportExcel222(devicename,deviceId){
    var templateId = 3;
    if(confirm("确定导出对应PMS模板数据吗？")){
        $("#exportimg").show();
        $.ajax({
            url : contextPath+ 'user/excel/exportAllDYPMS',
            data : {
                devicename : devicename,
                templateId : templateId,
                deviceId : deviceId,
                deviceType : pdtype,
                transformerCode : pdid
            },
            type : 'POST',
            success : function(data) {
                //alert(data.msgDesc);
                $("#exportimg").hide();
                if(data.msgDesc=="导出失败"){
                    alert(data.msgDesc);
                }else if(data.msgDesc=="none"){
                    alert("导出失败");
                }else{
                    // var uploadurl =  basePath +data.msgDesc;
                    var downloadurl=contextPath+ 'user/excel/download?filename='+data.msgDesc;
                    //alert(uploadurl);
                    window.location.href =downloadurl;
                }
            }
        });
    }
}
